package com.sistema.escola.domain.dao.usuario;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.RequestScoped;

import com.sistema.escola.domain.model.usuario.Usuario;

@Component
@RequestScoped
public class UsuarioDAO {

	private Criteria criteria;
	
	public UsuarioDAO(Session session) {
		this.criteria = session.createCriteria(Usuario.class, "u");
	}
	
	public Usuario findByEmailAndPassword(String email, String password) {
		this.criteria.add(Restrictions.eq("u.email", email));
		this.criteria.add(Restrictions.eq("u.password", password));
		return (Usuario) this.criteria.uniqueResult();
	}
	
}
